{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# LinearRegression"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "A implementation of Ordinary Least Squares simple and multiple linear regression."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> from mlxtend.regressor import LinearRegression"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Overview"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Illustration of a simple linear regression model:\n",
    "    \n",
    "![](./LinearRegression_files/simple_regression.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In Ordinary Least Squares (OLS) Linear Regression, our goal is to find the line (or hyperplane) that minimizes the vertical offsets. Or in other words, we define the best-fitting line as the line that minimizes the sum of squared errors (SSE) or mean squared error (MSE) between our target variable (y) and our predicted output over all samples $i$ in our dataset of size $n$.\n",
    "\n",
    "$$SSE =  \\sum_i \\big(\\text{target}^{(i)} - \\text{output}^{(i)}\\big)^2$$\n",
    "\n",
    "$$MSE = \\frac{1}{n} \\times SSE$$\n",
    "\n",
    "\n",
    "Now, `LinearRegression` implements a linear regression model for performing ordinary least squares regression using one of the following five approaches:\n",
    "\n",
    "- Normal Equations\n",
    "- QR Decomposition Method\n",
    "- SVD (Singular Value Decomposition) method\n",
    "- Gradient Descent\n",
    "- Stochastic Gradient Descent\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Normal Equations (closed-form solution)\n",
    "\n",
    "The closed-form solution should be preferred for \"smaller\" datasets where calculating (a \"costly\") matrix inverse is not a concern. For very large datasets, or datasets where the inverse of $[X^T X]$ may not exist (the matrix is non-invertible or singular, e.g., in case of perfect multicollinearity), the QR, SVD or gradient descent approaches are to be preferred.\n",
    "\n",
    "The linear function (linear regression model) is defined as:\n",
    "\n",
    "$$y = w_0x_0 + w_1x_1 + ... + w_mx_m = \\sum_{i=0}^{m} = \\mathbf{w}^T\\mathbf{x}$$\n",
    "\n",
    "where $y$ is the response variable, $\\mathbf{x}$ is an $m$-dimensional sample vector, and $\\mathbf{w}$ is the weight vector (vector of coefficients). Note that $w_0$ represents the y-axis intercept of the model and therefore $x_0=1$.  \n",
    "\n",
    "Using the closed-form solution (normal equation), we compute the weights of the model as follows:\n",
    "\n",
    "$$ \\mathbf{w} = (\\mathbf{X}^T\\mathbf{X})^{-1}\\mathbf{X}^Ty$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Stable OLS via QR Factorization\n",
    "\n",
    "The QR decomposition method offers a more numerically stable alternative to the closed-form, analytical solution based on the \"normal equations,\" and it can be used to compute the inverse of large matrices more efficiently.\n",
    "\n",
    "QR decomposition method decomposes given matrix into two matrices for which an inverse can be easily obtained. For instance, a given matrix $X \\in \\mathbb{R}^{n \\times m}$, the QR decomposition into two matrices is:\n",
    "\n",
    "$$\\mathbf{X = QR},$$\n",
    "\n",
    "where\n",
    "\n",
    "$Q \\in \\mathbb{R}^{n \\times m}$ is an orthonormal matrix, such that $Q^\\top Q = QQ^\\top = I$. \n",
    "The second matrix $R \\in \\mathbf{R}^{m \\times m}$ is an upper triangular matrix.\n",
    "\n",
    "The weight parameters of the ordinary least squares regression model can then be computed as follows [1]:\n",
    "\n",
    "$$\\mathbf{w} = \\mathbf{R}^{-1}\\mathbf{Q}^\\top y.$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Stable OLS via Singular Value Decomposition\n",
    "\n",
    "Another alternative way for obtaining the OLS model weights in a numerically stable fashion is by Singular Value Decomposition (SVD), which is defined as:\n",
    "\n",
    "$$\\mathbf{X}=\\mathbf{U}\\Sigma \\mathbf{V}^\\top,$$\n",
    "\n",
    "for a given matrix $\\mathbf{X}$.\n",
    "\n",
    "Then, it can be shown that the pseudo-inverse of $X$, $X^+$, can be obtained as follows [1]:\n",
    "\n",
    "$$ X^+ = \\mathbf{U} \\mathbf{\\Sigma}^+  V^{\\top}.$$\n",
    "\n",
    "Note that while $\\Sigma$ is the diagonal matrix consisting of singular values of $\\mathbf{X}$, $\\Sigma^{+}$ is the diagonal matrix consisting of the reciprocals of the singular values.\n",
    "\n",
    "The model weights can then be computed as follows:\n",
    "\n",
    "$$\\mathbf{w} = \\mathbf{X}^+  \\mathbf{y}.$$\n",
    "\n",
    "Please note that this OLS method is computationally most inefficient. However, it is a useful approach when the direct method (normal equations) or QR factorization cannot be applied or the normal equations (via $\\mathbf{X}^T \\mathbf{X}$) are ill-conditioned [3].\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Gradient Descent (GD)  and Stochastic Gradient Descent (SGD) "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "See [Gradient Descent and Stochastic Gradient Descent](../general_concepts/gradient-optimization.md) and [Deriving the Gradient Descent Rule for Linear Regression and Adaline](../general_concepts/linear-gradient-derivative.md) for details."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Random shuffling is implemented as:\n",
    "\n",
    "- for one or more epochs\n",
    "    - randomly shuffle samples in the training set\n",
    "        - for training sample *i*\n",
    "            - compute gradients and perform weight updates"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### References"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- [1] Chapter 3, page 55, Linear Methods for Regression. Trevor Hastie; Robert Tibshirani; Jerome Friedman (2009). [The Elements of Statistical Learning: Data Mining, Inference, and Prediction (2nd ed.)](http://statweb.stanford.edu/~tibs/ElemStatLearn/download.html). New York: Springer. (ISBN 978–0–387–84858–7)\n",
    "- [2] G. Strang, Linear Algebra and Its Applications, 2nd Ed., Orlando, FL, Academic Press, Inc., 1980, pp. 139-142.\n",
    "- [3] Douglas Wilhelm Harder. Numerical Analysis for Engineering. Section 4.8, [ill-conditioned Matrices](https://ece.uwaterloo.ca/~dwharder/NumericalAnalysis/04LinearAlgebra/illconditioned/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 1 - Closed Form Solution"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Intercept: 0.25\n",
      "Slope: 0.81\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAW4AAAD8CAYAAABXe05zAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAG11JREFUeJzt3WmUlOWZxvH/DdFhWjFgQKNR6XEyiYAIYgeDKCgo7vskxrRLEhVFNGqMDgZHYzwYVERQ2VpAUZugsskadtkFu9k3F5BGRaTVKEoDsjzz4W4nQVmqod56a7l+53Cq6+3qqrs+eJ3b530WCyEgIiKZo1rcBYiISNUouEVEMoyCW0Qkwyi4RUQyjIJbRCTDKLhFRDKMgltEJMMouEVEMoyCW0Qkw3wvijetU6dOyM/Pj+KtRUSyUmlp6SchhLqJvDaS4M7Pz6ekpCSKtxYRyUpmVpboazVUIiKSYRTcIiIZRsEtIpJhFNwiIhlGwS0ikmEU3CIiGUbBLSKSYRTcIiIHauNGuPtuWL8+JR+n4BYRORCjRkGDBvDkkzB+fEo+UsEtIrI/1q+Hq66CSy6B2rVhzhy4/vqUfLSCW0SkKkKAAQOgfn0YMQIefhhKS+HUU1NWQkLBbWZrzGyJmS00M21CIiK56d134eyz4YYboFEjWLQI7r+f4lcPJj8fqlWD/HwoLo62jKpsMnVWCOGTyCoREUlX27ZBt27w5z/DwQdDnz5w001QrRrFxdCuHVRU+EvLyvw5QGFh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kRkMlIiIZRsEtIpJhFNwiIhlGwS0ikmEU3CIiGUbBLSKSYRTcIiIZRsEtIpJh/g/fd/K2NzDSJgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from mlxtend.regressor import LinearRegression\n",
    "\n",
    "X = np.array([ 1.0, 2.1, 3.6, 4.2, 6])[:, np.newaxis]\n",
    "y = np.array([ 1.0, 2.0, 3.0, 4.0, 5.0])\n",
    "\n",
    "ne_lr = LinearRegression()\n",
    "ne_lr.fit(X, y)\n",
    "\n",
    "print('Intercept: %.2f' % ne_lr.b_)\n",
    "print('Slope: %.2f' % ne_lr.w_[0])\n",
    "\n",
    "def lin_regplot(X, y, model):\n",
    "    plt.scatter(X, y, c='blue')\n",
    "    plt.plot(X, model.predict(X), color='red')    \n",
    "    return\n",
    "\n",
    "lin_regplot(X, y, ne_lr)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2 - QR decomposition method"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Intercept: 0.25\n",
      "Slope: 0.81\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAW4AAAD8CAYAAABXe05zAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAG11JREFUeJzt3WmUlOWZxvH/DdFhWjFgQKNR6XEyiYAIYgeDKCgo7vskxrRLEhVFNGqMDgZHYzwYVERQ2VpAUZugsskadtkFu9k3F5BGRaTVKEoDsj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oFd64zs3zgZGBuvJVEq3LIYCGwAZgYQsjq71upO3AvsDPuQlIoABPMrNTM2sVdTMSOB8qB5yqHw/qZ2SFRfqCCOw2Y2aHAUODOEMLGuOuJUghhRwihCXAM0MzMsnpYzMwuAjaEEErjriXFWoQQmgLnAx0qh0Kz1feApkDvEMLJwCagY5QfqOCOWeVY71CgOIQwLO56UqXyfyVfB86LuZSotQAuqRzzHQy0NrOX4i0peiGEdZWPG4DhQLN4K4rUB8AH//J/j0PwII+MgjtGlTfr+gMrQgjd4q4namZW18xqVf7878DZwMp4q4pWCOG+EMIxIYR84FfAlBDCNTGXFSkzO6TyZjuVQwZtgaydLRZCWA+8b2Y/rbzUBoh0gsE+z5xMlVQdSpxmWgDXAksqx30B/hRCGBtjTVE6ChhoZtXxpuGVEEJOTI/LMUcCw70v4XvAoBDC3+MtKXK3A8WVM0pWA7+N8sPSZjqgiIgkRkMlIiIZRsEtIpJhFNwiIhlGwS0ikmEU3CIiGUbBLSKSYRTcIiIZRsEtIpJh/g/fd/K2NzDSJgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from mlxtend.regressor import LinearRegression\n",
    "\n",
    "X = np.array([ 1.0, 2.1, 3.6, 4.2, 6])[:, np.newaxis]\n",
    "y = np.array([ 1.0, 2.0, 3.0, 4.0, 5.0])\n",
    "\n",
    "qr_lr = LinearRegression(method='qr')\n",
    "qr_lr.fit(X, y)\n",
    "\n",
    "print('Intercept: %.2f' % qr_lr.b_)\n",
    "print('Slope: %.2f' % qr_lr.w_[0])\n",
    "\n",
    "def lin_regplot(X, y, model):\n",
    "    plt.scatter(X, y, c='blue')\n",
    "    plt.plot(X, model.predict(X), color='red')    \n",
    "    return\n",
    "\n",
    "lin_regplot(X, y, qr_lr)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 3 - SVD method"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Intercept: 0.25\n",
      "Slope: 0.81\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAW4AAAD8CAYAAABXe05zAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAG11JREFUeJzt3WmUlOWZxvH/DdFhWjFgQKNR6XEyiYAIYgeDKCgo7vskxrRLEhVFNGqMDgZHYzwYVERQ2VpAUZugsskadtkFu9k3F5BGRaTVKEoDsjzz4W4nQVmqod56a7l+53Cq6+3qqrs+eJ3b530WCyEgIiKZo1rcBYiISNUouEVEMoyCW0Qkwyi4RUQyjIJbRCTDKLhFRDKMgltEJMMouEVEMoyCW0Qkw3wvijetU6dOyM/Pj+KtRUSyUmlp6SchhLqJvDaS4M7Pz6ekpCSKtxYRyUpmVpboazVUIiKSYRTcIiIZRsEtIpJhFNwiIhlGwS0ikmEU3CIiGUbBLSKSYRTcIiIHauNGuPtuWL8+JR+n4BYRORCjRkGDBvDkkzB+fEo+UsEtIrI/1q+Hq66CSy6B2rVhzhy4/vqUfLSCW0SkKkKAAQOgfn0YMQIefhhKS+HUU1NWQkLBbWZrzGyJmS00M21CIiK56d134eyz4YYboFEjWLQI7r+f4lcPJj8fqlWD/HwoLo62jKpsMnVWCOGTyCoREUlX27ZBt27w5z/DwQdDnz5w001QrRrFxdCuHVRU+EvLyvw5QGFhNOVoqEREZG9KS6FZM+jYEc4/H1asgJtv9vYa6NTpn6H9jYoKvx6VRIM7ABPMrNTM2u3uBWbWzsxKzKykvLw8eRWKiMRh0yb44x89tD/+GIY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
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from mlxtend.regressor import LinearRegression\n",
    "\n",
    "X = np.array([ 1.0, 2.1, 3.6, 4.2, 6])[:, np.newaxis]\n",
    "y = np.array([ 1.0, 2.0, 3.0, 4.0, 5.0])\n",
    "\n",
    "svd_lr = LinearRegression(method='svd')\n",
    "svd_lr.fit(X, y)\n",
    "\n",
    "print('Intercept: %.2f' %svd_lr.b_)\n",
    "print('Slope: %.2f' % svd_lr.w_[0])\n",
    "\n",
    "def lin_regplot(X, y, model):\n",
    "    plt.scatter(X, y, c='blue')\n",
    "    plt.plot(X, model.predict(X), color='red')    \n",
    "    return\n",
    "\n",
    "lin_regplot(X, y, svd_lr)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 4 - Gradient Descent"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Iteration: 100/100 | Cost 0.08 | Elapsed: 0:00:00 | ETA: 0:00:00"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Intercept: 0.22\n",
      "Slope: 0.82\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAW4AAAD8CAYAAABXe05zAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAGzJJREFUeJzt3WmUVOW1xvH/Fo0R4pSAs9BJzEArItrggBcFicNVo7n3uoy214mIMWhi1GskRI1JICpRUQaRNA6YVoMIKjSKDAIyNNBMQjOIKI0ihiaiAo1M/d4Pu53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u560qXmfyUnA2fGXErUOgI/rVnzfQroYmb/iLek6IUQ3ql5XAeMAjrEW1Gk3gbe/sz/PY7AgzwyCu4Y1VysGwosDSHcG3c9UTOzFma2X83PewFdgWXxVhWtEELPEMJhIYQ84OfApBDCJTGXFSkza1ZzsZ2aJYPTgaydFgshvAu8ZWY/qnnqNCDSAYNa7zmZLum6KXGG6Qj8L7CoZt0X4PchhLEx1hSlg4HHzKwJ3jQMDyHkxHhcjjkQGOV9CbsDT4QQXoy3pMhdBxTXTJS8AVwR5YdlzDigiIikRkslIiIJo+AWEUkYBbeISMIouEVEEkbBLSKSMApuEZGEUXCLiCSMgltEJGH+H+yYASXcfDjCAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from mlxtend.regressor import LinearRegression\n",
    "\n",
    "X = np.array([ 1.0, 2.1, 3.6, 4.2, 6])[:, np.newaxis]\n",
    "y = np.array([ 1.0, 2.0, 3.0, 4.0, 5.0])\n",
    "\n",
    "gd_lr = LinearRegression(method='sgd',\n",
    "                         eta=0.005, \n",
    "                         epochs=100,\n",
    "                         minibatches=1,\n",
    "                         random_seed=123,\n",
    "                         print_progress=3)\n",
    "gd_lr.fit(X, y)\n",
    "\n",
    "print('Intercept: %.2f' % gd_lr.b_)\n",
    "print('Slope: %.2f' % gd_lr.w_)\n",
    "\n",
    "def lin_regplot(X, y, model):\n",
    "    plt.scatter(X, y, c='blue')\n",
    "    plt.plot(X, model.predict(X), color='red')    \n",
    "    return\n",
    "\n",
    "lin_regplot(X, y, gd_lr)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAagAAAEYCAYAAAAJeGK1AAAABHNCSVQICAgIfA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PgRfJhqr5UUS8WPChmo0KX0GZlUMMMz3cOtXkx4Pby+BnzO8je1L0KcC63EjcZqXmgDIrh/NyP+9N0/9MNqo6wAXAP6bpO4FLACS1pifgViWpBZgTEXeTPYjxCOCAqzizMvJfUmaNM0nS+tz8zyNioKt5h6T7yf5oPD+VfRy4TtJnyJ5w+9FU/glgpaSLya6ULiF74ms1rcB3JU0ne7DcFenx7Wal58+gzJosfQbVFRHPNrstZmXiW3xmZlZKvoIyM7NS8hWUmZmVkgPKzMxKyQFlZmal5IAyM7NSckCZmVkp/X/aSIidJzbOAAAAAUlEQVQtbechnQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Visualizing the cost to check for convergence and plotting the linear model:\n",
    "\n",
    "plt.plot(range(1, gd_lr.epochs+1), gd_lr.cost_)\n",
    "plt.xlabel('Epochs')\n",
    "plt.ylabel('Cost')\n",
    "plt.ylim([0, 0.2])\n",
    "plt.tight_layout()\n",
    "plt.show()    "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 5 - Stochastic Gradient Descent"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Intercept: 0.82\n",
      "Slope: 0.24\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAW4AAAD8CAYAAABXe05zAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAGxJJREFUeJzt3X2QlfV5//H3hREtocWh0oZ2gzsZ/P3Cgwi4Ai2QwWAlpJLpdEhHsk3EBx5CSswEcapgiygC9Qk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JhQ0MIA4HRwA9ahkJz1ReAgcDiEMIA4DTw91F+oII7Zi1jvb8AUiGEsrjryZSWf0puA74RcylRGwp8q2XM9zXg62a2Kt6SohdCaGx5PAKUA4PirShSHwAf/Na/Hn+OB3lkFNwxarlZtxzYH0J4Pu56omZm3czshpaffw+4E/h1vFVFK4TwaAihIIRQCNwDvBVC+NuYy4qUmX2x5WY7LUMGdwE5O1sshPD/gffN7P+2XBoJRDrBoNUzJzMlU4cSZ5mhwHeB+pZxX4DHQggbYqwpSt2BFWZ2Dd40rAkh5MX0uDzzx0C59yV8AVgdQngj3pIiNxVItcwoeRe4L8oPy5rpgCIikh4NlYiIJIyCW0QkYRTcIiIJo+AWEUkYBbeISMIouEVEEkbBLSKSMApuEZGE+R+EhfZyAyHEYwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from mlxtend.regressor import LinearRegression\n",
    "\n",
    "X = np.array([ 1.0, 2.1, 3.6, 4.2, 6])[:, np.newaxis]\n",
    "y = np.array([ 1.0, 2.0, 3.0, 4.0, 5.0])\n",
    "\n",
    "sgd_lr = LinearRegression(method='sgd',\n",
    "                          eta=0.01, \n",
    "                          epochs=100, \n",
    "                          random_seed=0, \n",
    "                          minibatches=len(y))\n",
    "sgd_lr.fit(X, y)\n",
    "\n",
    "print('Intercept: %.2f' % sgd_lr.w_)\n",
    "print('Slope: %.2f' % sgd_lr.b_)\n",
    "\n",
    "def lin_regplot(X, y, model):\n",
    "    plt.scatter(X, y, c='blue')\n",
    "    plt.plot(X, model.predict(X), color='red')    \n",
    "    return\n",
    "\n",
    "lin_regplot(X, y, sgd_lr)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoA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+LSIaJLUBc0qn10m+IuXnyZfJIemzQFVEfEHST4FOilPV/O+I6CzzqZqlwi0os8oQR7l/tG2GUjofXB9vXWP+FxS/KfpCYFXJTNxmFc0BZVYZbir5+XRy/9cUZ1UHuBX4P8n9x4E7ACRlk2/AHZKkDDA3Ip6k+EWM04C3teLMKpHfSZmdOBMlvViy/NOIGBhqXi3pWYpvGm9Jyv4IeFDSn1P8httPJeV/DDwg6dMUW0p3UPzG16Fkge9Imkrxi+W+lHx9u1nF8zUoszGWXINqiohdY10Xs0riLj4zM6tIbkGZmVlFcgvKzMwqkgPKzMwqkgPKzMwqkgPKzMwqkgPKzMwq0v8Fn/PcJaMofrMAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.plot(range(1, sgd_lr.epochs+1), sgd_lr.cost_)\n",
    "plt.xlabel('Epochs')\n",
    "plt.ylabel('Cost')\n",
    "plt.ylim([0, 0.2])\n",
    "plt.tight_layout()\n",
    "plt.show()  "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6 - Stochastic Gradient Descent with Minibatches"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Intercept: 0.24\n",
      "Slope: 0.82\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAW4AAAD8CAYAAABXe05zAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAGz1JREFUeJzt3Xl01fWZx/H3A9oFXFCh7iRapzUsypKyKhVBq9a2jlMcOmE8ehyRRSuH1tEW65Sx0CpaUU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geQsjqz1tlMPCfwL64C0mhAEwzszIz6x53MRE7G9gCPFY1HDbKzOpG+YYK7jRgZscAzwN9Qgjb464nSiGEyhBCM+AMoJWZZfWwmJldCWwOIZTFXUuKtQ8htAAuB3pXDYVmq6OAFsCwEEJz4HPgjijfUMEds6qx3ueBkhDCC3HXkypV/5ScDVwWcylRaw/8vGrM92ngYjMbF29J0QshfFD1fTMwAWgVb0WReh94///963E8HuSRUXDHqOpm3WhgdQjhr3HXEzUza2Bm9ap+/i7QGVgTb1XRCiH8LoRwRgghH+gKzAwhdIu5rEiZWd2qm+1UDRlcCmTtbLEQwofAe2b2w6pLnYBIJxgc9szJVEnVocRppj3w78DyqnFfgN+HEF6NsaYonQqMNbPaeNPwbAghJ6bH5ZiTgQnel3AU8GQIYUq8JUXuFqCkakbJO8D1Ub5Z2kwHFBGRxGioREQkwyi4RUQyjIJbRCTDKLhFRDKMgltEJMMouEVEMoyCW0Qkwyi4RUQyzP8CIO3yfplEP0gAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from mlxtend.regressor import LinearRegression\n",
    "\n",
    "X = np.array([ 1.0, 2.1, 3.6, 4.2, 6])[:, np.newaxis]\n",
    "y = np.array([ 1.0, 2.0, 3.0, 4.0, 5.0])\n",
    "\n",
    "sgd_lr = LinearRegression(method='sgd',\n",
    "                          eta=0.01, \n",
    "                          epochs=100, \n",
    "                          random_seed=0, \n",
    "                          minibatches=3)\n",
    "sgd_lr.fit(X, y)\n",
    "\n",
    "print('Intercept: %.2f' % sgd_lr.b_)\n",
    "print('Slope: %.2f' % sgd_lr.w_)\n",
    "\n",
    "def lin_regplot(X, y, model):\n",
    "    plt.scatter(X, y, c='blue')\n",
    "    plt.plot(X, model.predict(X), color='red')    \n",
    "    return\n",
    "\n",
    "lin_regplot(X, y, sgd_lr)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAagAAAEYCAYAAAAJeGK1AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAIABJREFUeJzt3Xl4HNWd7vHvT63FkmxJtiS8r9jEmM1gYXaSQEjMQDCZQDAh7DfOxk1mmEkGboZkhiRzJzczIcOEBEzYQlhCCAlOIHgI++JNNgYvYBDGi2zJli1rsfaWfvePLom2LFlbl9XI7+d5+lH3qVPVp1otvX2qTp8yd0dERCTZpAx2A0RERLqigBIRkaSkgBIRkaSkgBIRkaSkgBIRkaSkgBIRkaQUakCZ2Twz22hmJWZ2UxfLbzSzDWb2lpk9Z2aT45ZdbWbvBber48rnmNnaYJu3m5mFuQ8iIjI4LKzvQZlZBHgXOA8oBVYCl7v7hrg6nwSWu3u9mX0N+IS7X2Zmo4BioAhwYBUwx933mtkK4FvAMuBp4HZ3/0soOyEiIoMmzB7UXKDE3Te5ezPwKDA/voK7v+Du9cHDZcCE4P5ngGfdvdLd9wLPAvPMbCyQ4+5LPZasvwYuDnEfRERkkKSGuO3xwLa4x6XAKQepfz3Q3hPqat3xwa20i/IDmNlCYCFAdnb2nJkzZ/al7T16p7yW4RmpTBiZmdDtiogMdatWrdrt7oU91QszoLo6N9Tl8UQz+xKxw3kf72HdXm/T3RcBiwCKioq8uLi4p/b2yRn//jynTBvFT78wO6HbFREZ6sxsS2/qhXmIrxSYGPd4ArCjcyUz+xTwXeAid2/qYd1SPjwM2O02D4VIitHWpnkMRUTCEmZArQRmmNlUM0sHFgCL4yuY2YnAXcTCaVfcoiXAp81spJmNBD4NLHH3MqDWzE4NRu9dBTwZ4j50K5J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JCVy6GSa2Zq4x8+4e/tQ8wwzW07sQ+PlQdk3gXvN7NvErnB7bVD+LWCRmV1PrKf0NWJXfO1KBPiNmeUSu7DcbcHl20WSns5BiQyy4BxUkbvvHuy2iCQTHeITEZGkpB6UiIgkJfWgREQkKSmgREQkKSmgREQkKSmgREQkKSmgREQkKf1/r6EdopNRh/0AAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.plot(range(1, sgd_lr.epochs+1), sgd_lr.cost_)\n",
    "plt.xlabel('Epochs')\n",
    "plt.ylabel('Cost')\n",
    "plt.ylim([0, 0.2])\n",
    "plt.tight_layout()\n",
    "plt.show()  "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## API"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "## LinearRegression\n",
      "\n",
      "*LinearRegression(method='direct', eta=0.01, epochs=50, minibatches=None, random_seed=None, print_progress=0)*\n",
      "\n",
      "Ordinary least squares linear regression.\n",
      "\n",
      "**Parameters**\n",
      "\n",
      "- `method` : string (default: 'direct')\n",
      "\n",
      "    For gradient descent-based optimization, use `sgd` (see `minibatch`\n",
      "    parameter for further options). Otherwise, if `direct` (default),\n",
      "    the analytical method is used. For alternative, numerically more\n",
      "    stable solutions, use either `qr` (QR decomopisition) or `svd`\n",
      "    (Singular Value Decomposition).\n",
      "\n",
      "- `eta` : float (default: 0.01)\n",
      "\n",
      "    solver learning rate (between 0.0 and 1.0). Used with `method =`\n",
      "    `'sgd'`. (See `methods` parameter for details)\n",
      "\n",
      "- `epochs` : int (default: 50)\n",
      "\n",
      "    Passes over the training dataset.\n",
      "    Prior to each epoch, the dataset is shuffled\n",
      "    if `minibatches > 1` to prevent cycles in stochastic gradient descent.\n",
      "    Used with `method = 'sgd'`. (See `methods` parameter for details)\n",
      "\n",
      "- `minibatches` : int (default: None)\n",
      "\n",
      "    The number of minibatches for gradient-based optimization.\n",
      "    If None: Direct method, QR, or SVD method (see `method` parameter\n",
      "    for details)\n",
      "    If 1: Gradient Descent learning\n",
      "    If len(y): Stochastic Gradient Descent learning\n",
      "    If 1 < minibatches < len(y): Minibatch learning\n",
      "\n",
      "- `random_seed` : int (default: None)\n",
      "\n",
      "    Set random state for shuffling and initializing the weights. Used in\n",
      "    `method = 'sgd'`. (See `methods` parameter for details)\n",
      "\n",
      "- `print_progress` : int (default: 0)\n",
      "\n",
      "    Prints progress in fitting to stderr if `method = 'sgd'`.\n",
      "    0: No output\n",
      "    1: Epochs elapsed and cost\n",
      "    2: 1 plus time elapsed\n",
      "    3: 2 plus estimated time until completion\n",
      "\n",
      "**Attributes**\n",
      "\n",
      "- `w_` : 2d-array, shape={n_features, 1}\n",
      "\n",
      "    Model weights after fitting.\n",
      "\n",
      "- `b_` : 1d-array, shape={1,}\n",
      "\n",
      "    Bias unit after fitting.\n",
      "\n",
      "- `cost_` : list\n",
      "\n",
      "    Sum of squared errors after each epoch;\n",
      "    ignored if solver='normal equation'\n",
      "\n",
      "**Examples**\n",
      "\n",
      "For usage examples, please see\n",
      "    [http://rasbt.github.io/mlxtend/user_guide/regressor/LinearRegression/](http://rasbt.github.io/mlxtend/user_guide/regressor/LinearRegression/)\n",
      "\n",
      "### Methods\n",
      "\n",
      "<hr>\n",
      "\n",
      "*fit(X, y, init_params=True)*\n",
      "\n",
      "Learn model from training data.\n",
      "\n",
      "**Parameters**\n",
      "\n",
      "- `X` : {array-like, sparse matrix}, shape = [n_samples, n_features]\n",
      "\n",
      "    Training vectors, where n_samples is the number of samples and\n",
      "    n_features is the number of features.\n",
      "\n",
      "- `y` : array-like, shape = [n_samples]\n",
      "\n",
      "    Target values.\n",
      "\n",
      "- `init_params` : bool (default: True)\n",
      "\n",
      "    Re-initializes model parameters prior to fitting.\n",
      "    Set False to continue training with weights from\n",
      "    a previous model fitting.\n",
      "\n",
      "**Returns**\n",
      "\n",
      "- `self` : object\n",
      "\n",
      "\n",
      "<hr>\n",
      "\n",
      "*get_params(deep=True)*\n",
      "\n",
      "Get parameters for this estimator.\n",
      "\n",
      "**Parameters**\n",
      "\n",
      "- `deep` : boolean, optional\n",
      "\n",
      "    If True, will return the parameters for this estimator and\n",
      "    contained subobjects that are estimators.\n",
      "\n",
      "**Returns**\n",
      "\n",
      "- `params` : mapping of string to any\n",
      "\n",
      "    Parameter names mapped to their values.'\n",
      "\n",
      "    adapted from\n",
      "    https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/base.py\n",
      "    Author: Gael Varoquaux <gael.varoquaux@normalesup.org>\n",
      "    License: BSD 3 clause\n",
      "\n",
      "<hr>\n",
      "\n",
      "*predict(X)*\n",
      "\n",
      "Predict targets from X.\n",
      "\n",
      "**Parameters**\n",
      "\n",
      "- `X` : {array-like, sparse matrix}, shape = [n_samples, n_features]\n",
      "\n",
      "    Training vectors, where n_samples is the number of samples and\n",
      "    n_features is the number of features.\n",
      "\n",
      "**Returns**\n",
      "\n",
      "- `target_values` : array-like, shape = [n_samples]\n",
      "\n",
      "    Predicted target values.\n",
      "\n",
      "<hr>\n",
      "\n",
      "*set_params(**params)*\n",
      "\n",
      "Set the parameters of this estimator.\n",
      "The method works on simple estimators as well as on nested objects\n",
      "(such as pipelines). The latter have parameters of the form\n",
      "``<component>__<parameter>`` so that it's possible to update each\n",
      "component of a nested object.\n",
      "\n",
      "**Returns**\n",
      "\n",
      "self\n",
      "\n",
      "adapted from\n",
      "https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/base.py\n",
      "Author: Gael Varoquaux <gael.varoquaux@normalesup.org>\n",
      "License: BSD 3 clause\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "with open('../../api_modules/mlxtend.regressor/LinearRegression.md', 'r') as f:\n",
    "    print(f.read())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  },
  "toc": {
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
